package nio;

import java.nio.ByteBuffer;

public class ByteBufferTest {
    public static void main(String[] args) {

        ByteBuffer buffer = ByteBuffer.allocate(88);
        System.out.println(buffer);

        String value = "七哥测试NIO";
        buffer.put(value.getBytes());
        System.out.println(buffer);
        // 切换到读模式
        buffer.flip();
        System.out.println(buffer);

        byte[] v = new byte[buffer.remaining()];
        buffer.get(v);

        System.out.println(buffer);
        System.out.println(new String(v));
    }
}